import {
    Component,
    OnInit,
    Injector,
    ViewChild,
    ViewEncapsulation,
} from "@angular/core";
import {
    ParkingsBillingSchemeServiceProxy,
    ParkingDto,
    CreateParkingDto,
    UpdateParkingDto,
} from "@shared/service-proxies/service-proxies";
import * as moment from "moment";
import { LazyLoadEvent } from "primeng/components/common/lazyloadevent";
import { Paginator } from "primeng/components/paginator/paginator";
import { Table } from "primeng/components/table/table";

import { finalize } from "rxjs/operators";

import { AppComponentBase } from "@shared/common/app-component-base";
import { appModuleAnimation } from "@shared/animations/routerTransition";

import { ActivatedRoute, Router } from "@angular/router";
import { MessageService } from "primeng/api";

@Component({
    selector: "app-parkings-billing-scheme",
    templateUrl: "./parkings-billing-scheme.component.html",
    styleUrls: ["./parkings-billing-scheme.component.css"],
    animations: [appModuleAnimation()],
})
export class ParkingsBillingSchemeComponent
    extends AppComponentBase
    implements OnInit
{
    @ViewChild("dataTable") dataTable: Table;
    @ViewChild("paginator") paginator: Paginator;
    // @ViewChild("createOrEditParkingGuradModal")
    // createOrEditParkingGuradModal: CreateOrEditParkingGuardModalComponent;
    parkingid: number;
    parkingName: string;
    parkingCoce: string;
    neighbourhood_Name: string;
    neighbourhood_id: number;
    constructor(
        injector: Injector,
        private route: Router,
        private activeRoute: ActivatedRoute,
        private _parkingsBillingSchemeServiceProxy: ParkingsBillingSchemeServiceProxy
    ) {
        super(injector);
    }
    ngOnInit() {
        this.activeRoute.queryParams.subscribe((params) => {
            this.parkingid = params["parkingid"];
            this.parkingName = params["parkingName"];
            this.parkingCoce = params["parkingCoce"];
            this.neighbourhood_Name = params["neighbourhood_Name"];
            this.neighbourhood_id = params["neighbourhood_id"];
        });
    }
    getBillingScheme(event?: LazyLoadEvent): void {
        this._parkingsBillingSchemeServiceProxy
            .getAll(
                this.parkingid,null,
                this.primengTableHelper.getSorting(this.dataTable),
                this.primengTableHelper.getSkipCount(this.paginator, event),
                this.primengTableHelper.getMaxResultCount(this.paginator, event)
            )
            .pipe(
                finalize(() => this.primengTableHelper.hideLoadingIndicator())
            )
            .subscribe((result) => {
                console.log(result);
                this.primengTableHelper.records = result.items;
                this.primengTableHelper.totalRecordsCount = result.items.length;
                this.primengTableHelper.hideLoadingIndicator();
                console.log(result.items);
            });
    }
}
